//
//  ZNEmoticonPackage.swift
//  ZNWeibo
//
//  Created by FunctionMaker on 2017/9/7.
//  Copyright © 2017年 FunctionMaker. All rights reserved.
//

import UIKit

/// 表情包模型
class ZNEmoticonPackage: NSObject {
    
    /// 表情包分组名
    var groupName: String?
    /// 表情包分组图片名
    var bgImageName: String?
    /// 表情包目录，从目录下加载info.plist可以创建表情模型数组
    var directory: String? {
        didSet {
            guard let directory = directory,
                  let infoPath = Bundle.main.emoticonsBundle.path(forResource: "info.plist", ofType: nil, inDirectory: directory),
                  let emotis = NSArray(contentsOfFile: infoPath) as? [[String: String]],
                  let emotisModels = NSArray.yy_modelArray(with: ZNEmoticon.self, json: emotis) as? [ZNEmoticon]
            
            else {
                return
            }
            
            for emoticon in emotisModels {
                emoticon.directory = directory
            }
            
            // 设置表情
            emoticons += emotisModels
        }
    }
    
    /// 避免后续解包
    lazy var emoticons = [ZNEmoticon]()
    
    override var description: String {
        return yy_modelDescription()
    }
}
